package com.vrsys.task;

import java.util.TimerTask;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.vrsys.util.IDGenerator;

@Component("idSaveTask")
public class IDSaveTask extends TimerTask {
    private IDGenerator idGenerator;
    private Logger logger = LoggerFactory.getLogger(IDSaveTask.class);
    private boolean continueFlag = true;

    public IDSaveTask() {
    }

    @Override
    public void run() {
        if(continueFlag)
            try {
//                logger.info("saving ids...");
                idGenerator.saveIds();
            } catch (Exception e) {
//                logger.error(e.getMessage());
                e.printStackTrace();
            }
    }

    public boolean isContinueFlag() {
        return continueFlag;
    }

    public void setContinueFlag(boolean continueFlag) throws Exception {
        this.continueFlag = continueFlag;
        idGenerator.saveIds();
    }

    public IDGenerator getIdGenerator() {
        return idGenerator;
    }

    public void setIdGenerator(IDGenerator idGenerator) {
        this.idGenerator = idGenerator;
    }
}
